package com.kaibes.platform.menu;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kaibes.web.api.ApiLink;
import com.kaibes.web.api.ResponseApi;

@RestController
@RequestMapping("/menus")
public class MenuApi extends ResponseApi<Menu, MenuService> { 
    
    @PutMapping("/{id:\\d+}")
    @ApiLink("修改菜单，根据id")
    public ResponseEntity<Object> putById(@PathVariable Integer id, @RequestBody @Validated(PutMapping.class) Menu menu) {
        return super.putById(menu, id, "修改菜单成功", "修改菜单失败");
    }
    
    @PostMapping
    @ApiLink("创建菜单")
    public ResponseEntity<List<Number>> post(@RequestBody Menu menu) {
        return super.post(menu, "创建菜单成功", "创建菜单失败");
    }
    
    @ApiLink("删除菜单，根据id")
    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody List<Integer> ids) {
        return super.deleteById(ids, "删除菜单成功", "删除菜单失败");
    }
    
    @ApiLink("删除菜单，根据id")
    @DeleteMapping("/{id:\\d+}")
    public ResponseEntity<Object> delete(@PathVariable Integer id) {
        return super.deleteById(id, "删除菜单成功", "删除菜单失败");
    }
    
}
